<script setup>
import { onMounted, onBeforeMount, computed, defineProps, ref } from 'vue'
import comps from "@/components/utils/component_selector.js"
const { name, requestParams } = defineProps(["name", "requestParams"]);
import { createVm, initVm } from "@/models/VModel.js"
import meta from "@/data/card-data-meta.json";
import { http_get } from "@/utils/request.js"
import complex_meta from "@/data/type-complex-meta.json"

const vm = initVm(complex_meta, createVm(requestParams));


// vm.status.is_properties_visible = (meta, vm) => {
//   let data = vm.getModel("~").value;
//   return data?.entity && data.entity == true;
// }

// vm.status.is_imps_visible = (meta, vm) => {
//   let data = vm.getModel().value;
//   if (data) {
//     return !data.enum;
//   }
//   return false;
// }

// vm.status.is_enums_visible = (meta, vm) => {
//   let data = vm.getModel().value;
//   return data?.enum && data.enum == true;
// }

// vm.status.is_composit_visible = (meta, vm) => {
//   let data = vm.getModel("~").value;
//   if (data) {
//     return !(data.interface || data.enum);
//   }
//   return false;
// }


const filterModel = ref({
  "type": "ms.meta.Type",
  "s-name-eq": requestParams.name
});

onMounted(() => {
  getDetail();
});

function getDetail() {
  http_get("/data/find-one", filterModel.value, result => {
    vm.setData("~", result);
  });
}

function changeDetail(name) {
  filterModel.value["s-name-eq"] = name;
  getDetail();
}

function setMode() {
  let mode = vm.mode == "browse" ? "edit" : "browse";
  vm.setMode(mode);
}
</script>

<template>
  <div class="common-layout" :stretch="true">
    <el-container direction="vertical">
      <el-main>
        <div>
          <div>
            <el-text>
              实体类型：<el-button @click="changeDetail('ms.sys.view.View')">ms.sys.view.View</el-button>
              枚举类型：<el-button @click="changeDetail('ms.meta.Primitives')">ms.meta.Primitives</el-button><br />
              接口： <el-button @click="changeDetail('ms.basic.TreeNode')">ms.basic.TreeNode</el-button>
              属性很多：<el-button @click="changeDetail('bip.uimeta.bill_base')">bip.uimeta.bill_base</el-button>
            </el-text>
          </div>
          <el-input v-model="filterModel['s-name-eq']" placeholder="类型名称" clearable />
          <el-button @click="getDetail()">查 询</el-button>
          <el-button @click="setMode()">编 辑</el-button>
        </div>
        <component :is="comps(meta)" :meta="meta" :vm="vm" />
        <component :is="comps(complex_meta)" :meta="complex_meta" :vm="vm" />
      </el-main>
    </el-container>
  </div>
</template>